package com.zhang.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.zhang.common.DTO.RegisterDto;
import com.zhang.common.lang.Const;
import com.zhang.entity.User;
import com.zhang.mapper.UserMapper;
import com.zhang.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张立松
 * @since 2023-03-31
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public Boolean addUser(RegisterDto registerDto) {
        User user = new User();
        user.setPassword(SecureUtil.md5(registerDto.getPassword()));
        user.setNickname(registerDto.getNickname());
        user.setUsername(registerDto.getUsername());
        user.setCreated(LocalDateTime.now());
        user.setStatus(0);
        user.setAvatar(Const.Default_Avatar);
        return this.save(user);
    }
}
